package com.showgood.socket {
	import com.showgood.vo.BaseVO;
	import com.showgood.vo.VoFactory;
	import flash.utils.ByteArray;
	/**
	 * 单个VO的网络命令
	 * @author BianPeng
	 */
	public class SingleSocketCommand extends AbstractSocketCommand {
		
		private var _data:BaseVO;
		
		public function SingleSocketCommand(message:int, stamp:int, data:BaseVO = null) {
			super(message, stamp, SocketConsts.FLAG_SINGLE_VO);
			_data = data;
		}
		
		public function get data():BaseVO {
			return _data;
		}
		
		private function doPack(byteArray:ByteArray):void {
			byteArray.writeInt(this.stamp());
			byteArray.writeShort(this.flag());
			byteArray.writeInt(this.message());
			byteArray.writeInt(_data.vid);
			this.data.pack(byteArray);
		}
		
		override public function pack(byteArray:ByteArray):void {
			var bytes:ByteArray = new ByteArray();
			doPack(bytes);
			byteArray.writeShort(bytes.length);
			byteArray.writeBytes(bytes);
		}
		
		override public function unpack(byteArray:ByteArray):void {
			this.setMessage(byteArray.readInt());
			var id:int = byteArray.readInt();
			this._data = VoFactory.instance.create(id);
			this._data.unpack(byteArray);
		}
		
	}

}


